<template>
  <div style="width: 100%;height: 100%">
      <div style="width: 20%;margin: 0 auto;padding-top: 300px">
            <h2 style="text-align: center;padding: 20px;color: lavender">账号登录</h2>
          <el-form :model="loginData">
            <el-form-item>
              <el-input v-model="loginData.username" placeholder="账号"></el-input>
            </el-form-item>
            <el-form-item>
              <el-input v-model="loginData.password" placeholder="密码" type="password"></el-input>
            </el-form-item>
            <el-radio-group style="margin-bottom: 20px" v-model="loginData.type">
              <el-radio style="" :label="1">老师</el-radio>
              <el-radio :label="2"
              >学生</el-radio
              >
            </el-radio-group>
            <el-button type="success" @click="login" style="width: 100%">登录</el-button>
          </el-form>
      </div>
  </div>
</template>

<script>
export default {
  data(){
    return{
      loginData:{
        username:"",
        password:"",
        type:1
      }
    }
  },
  methods:{
    login(){
      if(this.loginData.type==1){
        //老师登陆
        this.request.post("/teacher/teacherLogin",this.loginData).then(resp=>{
            if(resp.code==200){
              localStorage.setItem("user", JSON.stringify(resp.data))
              //跳转到老师首页
              this.$router.push("/teacherAdmin")
              let name = JSON.parse(localStorage.getItem("user")).nickname
              this.$message.success("欢迎"+name+"老师使用本系统");
            }
        })
      }else{
        //学生登陆
        this.request.post("/student/studentLogin",this.loginData).then(resp=>{
          if(resp.code==200){
            //跳转到学生首页
			localStorage.setItem("user", JSON.stringify(resp.data))
            this.$router.push("/selectCourse")
          }
        })
      }
    }
  }
}
</script>

<style>
html,body{
  width: 100%;
  height: 100%;
  background-color: rgb(60, 60, 68);
}
</style>